package cn.com.test.common.mysql;

import cn.com.test.common.constants.ConstantUtil;

import java.sql.Connection;
import java.sql.DriverManager;

public class ConnectionFactory {

	public static Connection getConnection() {
		Connection con = null;
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			System.out.println(ConstantUtil.MYSQL_CONNECTION_URL);
			con = DriverManager.getConnection(ConstantUtil.MYSQL_CONNECTION_URL, ConstantUtil.MYSQL_USERNAME,
					ConstantUtil.MYSQL_PASSWORD);
			if (con != null) {
				System.out.println("数据库连接成功！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("数据库连接失败！");
		}
		return con;
	}
}
